package com.alumni_circle.core.utils;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * @author 龙小虬
 * @since 2020-07-20 22:09
 */
@Component
public class MetaHandler implements MetaObjectHandler {

    /**
     * 新增数据执行
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        Object createBy = getFieldValByName("createBy",metaObject);
        Object createName = getFieldValByName("createName",metaObject);
        this.setFieldValByName("createTime", StringTime.time(), metaObject);
        this.setFieldValByName("updateName", createName, metaObject);
        this.setFieldValByName("updateTime", StringTime.time(), metaObject);
        this.setFieldValByName("updateBy", createBy, metaObject);
    }

    /**
     * 更新数据执行
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", StringTime.time(), metaObject);
    }

}